<?
if ($fsubmit == NULL) {
    ?>
    <form method = "post" action="<? echo $PHP_SELF ?>">
        INVENTORY FORM<p>
            <input type="radio" name="inputtype" value="1"> Receving
            <input type="radio" name="inputtype" value="2"> Withdraw
        <br><p>
            Part Name: <input type="text" name="fname"><br>
            Part Amount: <input type="text" name="famount"><br>
        <p>
            <input type="submit"name="fsubmit" value="SUBMIT">
            <input type ="reset" name="freset" value="CLEAR">
    </form>
<?
} else {
    $link = mysql_connect("localhost", "root", "1234");
    $sql = "use inventory57";
    $result = mysql_query($sql);

    $sql = "select* from info where inv_name='$fname'";
    $dbquery = mysql_query($sql);
    $dbarr = mysql_fetch_array($dbquery);

    if ($dbarr) {
        if ($inputtype == 1) {
            $newamount = $dbarr['inv_amount'] + $famount;
            echo "New Amount = " . $dbarr['inv_amount'] . " + " . $famount . "=" . $newamount;
        } else {
            $newamount = $dbarr['inv_amount'] - $famount;
            if ($newamount <= 0) {
                $newamount = 0;
            }
            echo "New Amount = " . $dbarr['inv_amount'] . "-" . $famount . "=" . $newamount;
            echo"<br>";
            echo "Withdraw only" . $dbarr['inv_amount'];
        }

        $sqlupdate = "update info set inv_amount = '$newamount ' where inv_name='$fname' ";
        $resultupdate = mysql_query($sqlupdate);
        mysql_close($link);
    } else {
        echo "GO TO ADD FROM";
    }
}
?>